package com.yan.iterator;

import java.util.Collection;
import java.util.Iterator;

@SuppressWarnings("all")
public class ProjectContainer implements Iterable<IProject> {
    private IProject[] projects;
    private int cursor;

    public ProjectContainer(Collection<IProject> projects) {
        this.projects = projects.toArray(new IProject[]{});
    }

    @Override
    public Iterator<IProject> iterator() {
        return new ProjectIterator();
    }

    private class ProjectIterator implements Iterator<IProject> {
        @Override
        public boolean hasNext() {
            return cursor != projects.length;
        }

        @Override
        public IProject next() {
            return projects[cursor++];
        }
    }
}

